﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietThinks.Website.Controllers;
using System.Net;
using VietThinks.Web.Mvc;
namespace VietThinks.Website.Controllers
{
    public class ErrorController : ApplicationController
    {
        public ActionResult Show()
        {
            this.Response.TrySkipIisCustomErrors = true;
            this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            this.ViewData["Description"] = this.TempData["Description"];
            this.ViewData["Source"] = this.TempData["Source"];
            this.ViewData["StackTrace"] = this.TempData["StackTrace"];

            return this.View();
        }

        public ViewResult Forbidden(string path)
        {
            this.Response.TrySkipIisCustomErrors = true;
            this.Response.StatusCode = (int)HttpStatusCode.Forbidden;

            ViewData["path"] = string.IsNullOrEmpty(path) ? this.Request.Url.AbsoluteUri : path;

            return this.View();
        }

        public ViewResult UnresolvableRequest(string path)
        {
            this.Response.TrySkipIisCustomErrors = true;
            this.Response.StatusCode = (int)HttpStatusCode.NotFound;

            ViewData["path"] = string.IsNullOrEmpty(path) ? this.Request.Url.AbsoluteUri : path;

            return this.View();
        }

        protected override void HandleUnknownAction(string actionName)
        {
            this.RedirectToAction(c => c.UnresolvableRequest(this.Request.Url.AbsoluteUri))
                .ExecuteResult(this.ControllerContext);
        }
    }
}
